using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spread.Common.Features.Sample;
using Spread.Common.DataStore;
using FarPoint.Win.Spread;

namespace Spread.PDFExport
{
    public partial class Introduction : BaseSampleControl
    {
        public Introduction()
        {
            InitializeComponent();
            SetupSpreadSheet();
        }
        private void SetupSpreadSheet()
        {
            Name = "Introduction";
            sheetView.DataAutoSizeColumns = false;
            sheetView.ColumnHeader.Rows[0].Height = 30;
            sheetView.ColumnHeader.Rows[0].Height = 30;
            sheetView.Rows.Default.Height = 25;
            sheetView.Columns.Default.Width = 90;
            sheetView.DataSource = new DataService().AccessDataSource.GetNWINDData("Products"); 
        }
        private void ExportButton_Clicked(object sender,EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Pdf file (*.pdf) | *.pdf";
            saveFileDialog.Title = "Save Spread to PDF Format.";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                PrintInfo printInfo = new PrintInfo();
                printInfo.ShowColor = true;
                printInfo.PdfFileName = saveFileDialog.FileName;
                printInfo.PrintToPdf = true;
                sheetView.PrintInfo = printInfo;
                spread.PrintSheet(sheetView);
            }
        }
    }
}


//
//Introduction.Designer.cs
//


namespace Spread.PDFExport
{
    partial class Introduction
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.spread = new FarPoint.Win.Spread.FpSpread();
            this.sheetView = new FarPoint.Win.Spread.SheetView();
            this.exportButton = new System.Windows.Forms.Button();
            this.pnlMain.SuspendLayout();
            this.pnlControls.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.spread)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.sheetView)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this.spread);
            // 
            // pnlControls
            // 
            this.pnlControls.Controls.Add(this.exportButton);
            // 
            // spread
            // 
            this.spread.Dock = System.Windows.Forms.DockStyle.Fill;
            this.spread.Location = new System.Drawing.Point(0, 0);
            this.spread.Name = "spread";
            this.spread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
            this.sheetView});
            this.spread.Size = new System.Drawing.Size(477, 487);
            this.spread.TabIndex = 0;
            // 
            // sheetView
            // 
            this.sheetView.Reset();
            this.sheetView.SheetName = "Introduction";
            // Formulas and custom names must be loaded with R1C1 reference style
            this.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
            this.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
            // 
            // exportButton
            // 
            this.exportButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.exportButton.Location = new System.Drawing.Point(6, 39);
            this.exportButton.Name = "exportButton";
            this.exportButton.Size = new System.Drawing.Size(148, 23);
            this.exportButton.TabIndex = 0;
            this.exportButton.Text = "Export to PDF";
            this.exportButton.UseVisualStyleBackColor = true;
            this.exportButton.Click += new System.EventHandler(this.ExportButton_Clicked);
            // 
            // Introduction
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "Introduction";
            this.pnlMain.ResumeLayout(false);
            this.pnlControls.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.spread)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.sheetView)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private FarPoint.Win.Spread.FpSpread spread;
        private FarPoint.Win.Spread.SheetView sheetView;
        private System.Windows.Forms.Button exportButton;
    }
}
